<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="/public/static/h-ui/css/H-ui.min.css" />
</head>
<body>
<article class="cl pd-20">
    <form action="" method="post" class="form form-horizontal" id="">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" autocomplete="off" value="{$info.title}" placeholder="标题" class="input-text" id="title">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>视频路径：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea type="text" autocomplete="off" placeholder="视频路径" style="height: 70px;" class="input-text" id="video_url">{$info.url}</textarea>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>视频封面：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <p style="height: 165px;width:165px;border: dashed 1px #e5e5e5">
                    <img src="{$info.img}" alt="" id="imgbrand_pic" class="thumbnail">
                </p>
                <div class="upload-btn" style="display: block">
				<span>
					<input name="file_upload" style="display: none" id="uploadImg" type="file" onchange="imgUpload(this);">
					<input type="hidden" value="{$info.img}" id="brand_pic" />
				</span>
                    <input  class="btn radius btn-secondary" onclick="on_upload()" type="button" value="上传图片" style="background-color: #e6e6e6;border-color: #e6e6e6;color:#666;position: absolute;top:80px;left:200px;font-size: 12px;">
                </div>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" onclick="addSuppAjax()" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
        <input type="hidden" value="{$info.id}" id="id">
    </form>
</article>
<script type="text/javascript" src="/public/js/jquery-2.1.1.js"></script>
<script type="text/javascript" src="/public/static/layer/2.4/layer.js"></script>
<script src="/public/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="/public/js/file_upload.js" type="text/javascript"></script>
<script type="text/javascript">
    function on_upload() {
        $("#uploadImg").trigger("click");
    }
    //模块输入信息验证
    function verify() {
        var title = $("#title").val();
        var video_url = $("#video_url").val();
        var brand_pic=$("#brand_pic").val();
        if (title == '') {
            layer.msg('标题不能为空',{icon:5,time:1000});
            return false;
        }
        if (video_url == '') {
            layer.msg('不能为空',{icon:5,time:1000});
            return false;
        }
        if (brand_pic == '') {
            layer.msg('图片不能为空',{icon:5,time:1000});
            return false;
        }
        return true;
    }
    var flag = false;//防止重复提交
    //添加用户
    function addSuppAjax() {
        var id = $("#id").val();
        var title = $("#title").val();
        var video_url = $("#video_url").val();
        var brand_pic=$("#brand_pic").val();
        if(verify() && !flag){
            flag = true;
            $.ajax({
                type : "post",
                url : "__CONF_SITE__admin/Video/video_edit",
                data : {
                    'id':id,
                    'title':title,
                    'video_url' : video_url,
                    'brand_pic' : brand_pic,
                },
                success : function(data) {
                    if(data['code']>0){
                        layer.msg('添加成功!',{icon:1,time:1000},function () {
                            window.parent.location.reload();
                        });
                    }
                    else{
                        flag = false;
                        layer.msg('添加失败',{icon:5,time:1000});
                    }
                }
            });
        }
    }
    //图片上传
    function imgUpload(event) {
        var fileid = $(event).attr("id");
        var str = $(event).next().attr("id");
        var data = { 'file_path' : "article_class/" };
        uploadFile(fileid,data,function(res){
            if(res.code){
                $("#img"+str).attr("src",res.data);
                $("#"+str).val(res.data);
                layer.msg(res.message,{icon:1,time:1000});
            }else{
                layer.msg(res.message,{icon:1,time:1000});
            }
        });
    }
</script>
</body>
</html>